package org.dromara.system.controller.system;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.bean.domain.vo.HisPatientVo;
import org.dromara.bean.domain.bo.HisPatientBo;
import org.dromara.bean.service.IHisPatientService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 就诊卡
 *
 * @author Lion Li
 * @date 2024-11-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/patient")
public class HisPatientController extends BaseController {

    private final IHisPatientService hisPatientService;


    /**
     * 查询就诊卡列表
     */
    @SaCheckPermission("system:patient:list")
    @GetMapping("/list")
    public TableDataInfo<HisPatientVo> list(HisPatientBo bo, PageQuery pageQuery) {
        return hisPatientService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出就诊卡列表
     */
    @SaCheckPermission("system:patient:export")
    @Log(title = "就诊卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HisPatientBo bo, HttpServletResponse response) {
        List<HisPatientVo> list = hisPatientService.queryList(bo);
        ExcelUtil.exportExcel(list, "就诊卡", HisPatientVo.class, response);
    }

    /**
     * 获取就诊卡详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:patient:query")
    @GetMapping("/{id}")
    public R<HisPatientVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(hisPatientService.queryById(id));
    }


    /**
     * 删除就诊卡
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:patient:remove")
    @Log(title = "就诊卡", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(hisPatientService.deleteWithValidByIds(List.of(ids), true));
    }
}
